/**
 * 
 */
package com.whu.waterworks.action;

import java.util.ArrayList;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.whu.waterworks.model.Antisseptic;
import com.whu.waterworks.service.AntissepticService;

/**
 * @author： Joymin
 * @date：2016-4-5 下午9:04:25
 * 说明: 
 */
public class AntissepticAction extends ActionSupport{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -9023779822273307156L;
	private AntissepticService antissepticService;
	private Antisseptic  antisseptic;
	private String jonsStrOfName;
	private ArrayList<Antisseptic>  rsAntisseptic;
	private String type;
	private String id;
	
	@SuppressWarnings("finally")
	public String addAntisseptic(){
		System.out.println("type="+type);
		String message="";
		ActionContext ctx = ActionContext.getContext();
		if(null!=antisseptic.getId()){
			id=antisseptic.getId().toString();
		}		
		try{
			message=antissepticService.addAntisseptic(antisseptic, type);			
		}catch(Exception e){
			e.printStackTrace();
			message="提交失败，请稍后！";
			return message;
		}finally{
			System.out.println(message);
			if(type.equals("1")){
				ctx.put("message", message);//往request里放入req
				ctx.put("urladdress", "./waterQuality/limitOfAntissepticInfo.jsp");//往request里放入req
			}else{
				if(null==id || id.equals("")){
					ctx.put("message", message);//往request里放入req
					ctx.put("urladdress", "./waterQuality/dataOfAntissepticInfo.jsp");//往request里放入req
				}else{
					ctx.put("message", message);//往request里放入req
					ctx.put("urladdress", "./waterQuality/requireAntissepticInfo.jsp");//往request里放入req
				}
			}
				
			return SUCCESS;  
		}		
	}
	
	public String getAntissepticById(){
		System.out.println("getAntissepticById start");
		System.out.println("id="+id);
		try{			
			antisseptic=antissepticService.getAntissepticById(id);
  	  		return SUCCESS;
		}catch(Exception e){
			e.printStackTrace();			
			return "exception";
		}finally{
			System.out.println("getAntissepticById end");
		}
	}

	public String getDataOfAntissepticNorm(){
		System.out.println("getDataOfLimitNorm start");
		ActionContext ctx = ActionContext.getContext();
		try{			
			antisseptic=antissepticService.getDataOfAntissepticNorm();			
  	  		return SUCCESS;
		}catch(Exception e){
			e.printStackTrace();
			ctx.put("message", "");//往request里放入req
			ctx.put("urladdress", "./waterQuality/limitOfAntissepticInfo.jsp");//往request里放入req
			return "exception";
		}finally{
			System.out.println("getDataOfLimitNorm end");
		} 
	}
	
	@SuppressWarnings("finally")
	public String delAntisseptic(){
		System.out.println("delAntissepticol start");
		ActionContext ctx = ActionContext.getContext();
		String message="";
		//删除数据
		if(null==antisseptic || null==type){
			try{
				antisseptic=new Antisseptic();
				antisseptic.setId(Integer.valueOf(id));
				message=antissepticService.delAntisseptic(antisseptic);			
	  	  		return SUCCESS;
			}catch (Exception e) {
				e.printStackTrace();			
				return SUCCESS;
			}finally{
				ctx.put("message", message);//往request里放入req
				ctx.put("urladdress", "./waterQuality/requireAntissepticInfo.jsp");//往request里放入req
				return SUCCESS;
			}		
		}else{  //删除限值
			try{			
				message=antissepticService.delAntisseptic(antisseptic);			
	  	  		return SUCCESS;
			}catch(Exception e){
				e.printStackTrace();			
				return SUCCESS;
			}finally{			
				ctx.put("message", message);//往request里放入req
				ctx.put("urladdress", "./waterQuality/limitOfAntissepticInfo.jsp");//往request里放入req
				return SUCCESS;
			}
		}		
		 
	}

	public AntissepticService getAntissepticService() {
		return antissepticService;
	}

	public void setAntissepticService(AntissepticService antissepticService) {
		this.antissepticService = antissepticService;
	}

	public Antisseptic getAntisseptic() {
		return antisseptic;
	}

	public void setAntisseptic(Antisseptic antisseptic) {
		this.antisseptic = antisseptic;
	}

	public String getJonsStrOfName() {
		return jonsStrOfName;
	}

	public void setJonsStrOfName(String jonsStrOfName) {
		this.jonsStrOfName = jonsStrOfName;
	}

	public ArrayList<Antisseptic> getRsAntisseptic() {
		return rsAntisseptic;
	}

	public void setRsAntisseptic(ArrayList<Antisseptic> rsAntisseptic) {
		this.rsAntisseptic = rsAntisseptic;
	}
	
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

}
